﻿/// <summary>
/// 列表子项画师
/// Author: LXF
/// </summary>

using UnityEngine;
using UnityEngine.UI;

public class ScrollListDrawer : MonoBehaviour {
    UGUIWrapContent infinityGridLayoutGroup;

    int amount = 10;

    void Start() {
        //初始化数据列表//
        infinityGridLayoutGroup = transform.GetComponent<UGUIWrapContent>();
        infinityGridLayoutGroup.SetAmount(amount);
        infinityGridLayoutGroup.updateChildrenCallback = UpdateChildrenCallback;
    }


    void OnGUI() {
        if (GUILayout.Button("Add one item")) {
            infinityGridLayoutGroup.SetAmount(++amount);
        }
    }

    void UpdateChildrenCallback(int index, Transform trans) {
        OnDraw(index, trans);
    }

    private void OnDraw(int index, Transform trans) {
        Text text = trans.Find("Text").GetComponent<Text>();
        text.text = index.ToString();
    }

}
